﻿#pragma execution_character_set("utf-8")
#include "database.h"
#include <QDebug>
#define DATA_BASE_NAME ("sql.db")//数据库文件名
QSqlDatabase DataBasePri::database;

DataBasePri::DataBasePri()
{
    if (QSqlDatabase::contains("sqllite")) {//连接数据库
        database = QSqlDatabase::database("sqllite");
    } else {
        database = QSqlDatabase::addDatabase("QSQLITE","sqllite");
    }
    database.setDatabaseName("sql.db");//设置数据库文件名
    database.setUserName("root");//用户
    database.setPassword("nopassword");//密码-无密码
    if (! database.open()){//打开数据库
        qCritical() << database.lastError().text();
        return;
    }

    QSqlQuery query(database);
    //超级管理
    bool ret = false;
    //质检表
    //  ret=query.exec(QString::fromLocal8Bit("drop TABLE quality;"));
    ret=query.exec(QString::fromLocal8Bit("CREATE TABLE quality (id INTEGER PRIMARY KEY AUTOINCREMENT,order_id TEXT UNIQUE NOT NULL,status TEXT not null default '未质检',quality_pic TEXT,created_at TEXT DEFAULT (datetime('now','localtime')),inspector TEXT ,FOREIGN KEY(order_id) REFERENCES orders(id),FOREIGN KEY(inspector) REFERENCES user(phone));"));
    //ret=query.exec(QString::fromLocal8Bit("TRUNCATE TABLE orders;"));

    //用户
    //ret = query.exec(QString::fromLocal8Bit("create table user(phone varchar(50) primary key,name varchar(50),passwd varchar(50),age varchar(50),sex varchar(50),root varchar(50))"));
    ret = query.exec(QString::fromLocal8Bit("create table user(phone varchar(50) primary key,name varchar(50),passwd varchar(50),age varchar(50),sex varchar(50),root varchar(50))"));
    ret= query.exec(QString::fromLocal8Bit("create table user(phone varchar(20) primary key,name varchar(50) not null,passwd varchar(100) not null,age int,sex varchar(10),root varchar(10) not null)"));
    ret = query.exec(QString::fromLocal8Bit("insert into user values('15826091031','唐梦璇','15826091031','22','女','false')"));
    ret = query.exec(QString::fromLocal8Bit("insert into user values('15923631755','宋知行','15923631755','20','女','false')"));
    ret = query.exec(QString::fromLocal8Bit("insert into user values('admin','admin','admin','23','女','true')"));

    //商品
    //ret = query.exec(QString::fromLocal8Bit("create table products(id varchar(50) primary key,name varchar(50),num varchar(50),type varchar(50),cost varchar(50),price varchar(50),remarks varchar(100),image varchar(50))"));
    //ret=query.exec(QString::fromLocal8Bit("TRUNCATE TABLE users;"));
    ret=query.exec(QString::fromLocal8Bit("create table products(id varchar(50) primary key,name varchar(50) not null,num int not null check (num>=0),type varchar(50),cost decimal(10,2) not null check (cost>=0),price decimal(10,2) not null check (price>=0),remarks varchar(100),image varchar(255))"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('e24d35','翡翠玉珠','3','翡翠','220','500','无','e24d35.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('c1g435','玛瑙手链','3','玛瑙','230','600','无','c1g435.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('a2b3c4','和田玉手镯','5','和田玉','300','800','优质和田玉','a2b3c4.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('d4e5f6','岫岩玉挂件','8','岫岩玉','150','400','天然纹理','d4e5f6.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('g7h8i9','独山玉雕','6','独山玉','200','450','手工雕刻','g7h8i9.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('j1k2l3','绿松石项链','10','绿松石','180','350','波斯绿松','j1k2l3.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('m4n5o6','青金石耳环','12','青金石','120','300','天然原石','m4n5o6.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('p7q8r9','琥珀戒指','7','琥珀','250','600','波罗的海','p7q8r9.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('s1t2u3','水晶摆件','4','水晶','100','250','紫水晶簇','s1t2u3.png')"));
    ret = query.exec(QString::fromLocal8Bit("insert into products values('v4w5x6','海蓝宝','9','海蓝宝','170','400','汉代工艺','v4w5x6.png')"));

    //供应商
    //ret = query.exec(QString::fromLocal8Bit("create table supplier(name varchar(50) primary key,place varchar(50),phone varchar(50),legalerson varchar(50),email varchar(50))"));
    ret=query.exec(QString::fromLocal8Bit("create table supplier(name varchar(50) primary key,place varchar(100),phone varchar(20),legalperson varchar(50),email varchar(100))"));
    ret = query.exec(QString::fromLocal8Bit("insert into supplier values('上海玉石有限公司','上海清河路18号     ','13335252525','张三','3031000@qq.com')"));
    ret = query.exec(QString::fromLocal8Bit("insert into supplier values('重庆商务有限公司','重庆解放碑33号附一号','15335252521','李四','3231000@qq.com')"));

    //订单
   // ret=query.exec(QString::fromLocal8Bit("drop TABLE orders;"));
ret=query.exec(QString::fromLocal8Bit("create table orders(id varchar(50) primary key,name varchar(50) not null,num int not null check (num > 0),type varchar(50),cost decimal(10, 2) not null check (cost >= 0),price decimal(10, 2) not null check (price >= 0),remarks varchar(100),supplier varchar(50),foreign key (supplier) references supplier(name))"));
//ret=query.exec(QString::fromLocal8Bit("ALTER TABLE orders DROP COLUMN status;"));
//ret=query.exec(QString::fromLocal8Bit("ALTER TABLE orders DROP COLUMN quality_pic;"));
//ret=query.exec(QString::fromLocal8Bit("TRUNCATE TABLE orders;"));
  //ret=query.exec(QString::fromLocal8Bit("  ALTER TABLE orders ADD COLUMN status VARCHAR(20) DEFAULT '待质检';"));
 // ret= query.exec(QString::fromLocal8Bit("  ALTER TABLE orders ADD COLUMN quality_pic VARCHAR(255);"));
    ret = query.exec(QString::fromLocal8Bit("insert into orders values('e24d35','翡翠玉珠','3','翡翠','220','500','无','上海玉石有限公司')"));
    ret = query.exec(QString::fromLocal8Bit("insert into orders values('c1g435','玛瑙手链','3','玛瑙','230','600','无','重庆商务有限公司')"));
    ret = query.exec(QString::fromLocal8Bit("insert into orders values('a2b3c4','和田玉手镯','5','和田玉','300','800','精品款','上海玉石有限公司')"));
    ret = query.exec(QString::fromLocal8Bit("insert into orders values('d4e5f6','岫岩玉挂件','8','岫岩玉','150','400','特价促销','重庆商务有限公司')"));
    ret = query.exec(QString::fromLocal8Bit("insert into orders values('g7i8hh9','海蓝宝','8','海蓝宝','170','400','汉代工艺','上海玉石有限公司')"));
    if (!ret) {
        qDebug() << "SQL Error:" << query.lastError().text();
    }
    //入库记录
    //ret = query.exec(QString::fromLocal8Bit("create table warehousing(time varchar(50) primary key,id varchar(50),name varchar(50),num varchar(50),type varchar(50),cost varchar(50),price varchar(50),remarks varchar(100))"));
   // ret=query.exec(QString::fromLocal8Bit("create table warehousing(id varchar(50), time timestamp default current_timestamp, name varchar(50) not null, num int not null check (num > 0), type varchar(50), cost decimal(10, 2) not null check (cost >= 0), price decimal(10, 2) not null check (price >= 0), remarks varchar(100), primary key (id), foreign key (id) references products(id))"));

    ret = query.exec(QString::fromLocal8Bit("CREATE TABLE warehousing (record_id INTEGER PRIMARY KEY AUTOINCREMENT,  time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, name VARCHAR(50) NOT NULL, num INT NOT NULL CHECK (num > 0), type VARCHAR(50), cost DECIMAL(10, 2) NOT NULL CHECK (cost >= 0), price DECIMAL(10, 2) NOT NULL CHECK (price >= 0), remarks VARCHAR(100), product_id VARCHAR(50) NOT NULL,FOREIGN KEY (product_id) REFERENCES products(id));"));

    ret = query.exec(QString::fromLocal8Bit("insert into warehousing (product_id, name, num, type, cost, price, remarks) values('e24d35', '翡翠玉珠', 22, '翡翠', 230.00, 6000.00, '无')"));
    ret = query.exec(QString::fromLocal8Bit("insert into warehousing (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 33, '玛瑙', 230.00, 3000.00, '无')"));
    ret = query.exec(QString::fromLocal8Bit("insert into warehousing (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 23, '玛瑙', 230.00, 6000.00, '无')"));
    ret = query.exec(QString::fromLocal8Bit("insert into warehousing (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 33, '玛瑙', 230.00, 2000.00, '无')"));
    ret = query.exec(QString::fromLocal8Bit("insert into warehousing (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 32, '玛瑙', 230.00, 6000.00, '无')"));
    ret = query.exec(QString::fromLocal8Bit("insert into warehousing (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 31, '玛瑙', 230.00, 3000.00, '无')"));
    ret = query.exec(QString::fromLocal8Bit("insert into warehousing (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 31, '玛瑙', 230.00, 6000.00, '无')"));
    ret = query.exec(QString::fromLocal8Bit("insert into warehousing (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 8000.00, '无')"));
//    ret = query.exec(QString::fromLocal8Bit("insert into warehousing values('2025-02-01-22-22-12','e24d35','翡翠玉珠','22','翡翠','230','6000','无')"));
//    ret = query.exec(QString::fromLocal8Bit("insert into warehousing values('2025-02-02-22-12-32','c1g435','玛瑙手链','33','玛瑙','230','3000','无')"));
//    ret = query.exec(QString::fromLocal8Bit("insert into warehousing values('2025-02-03-22-12-32','c1g435','玛瑙手链','23','玛瑙','230','6000','无')"));
//    ret = query.exec(QString::fromLocal8Bit("insert into warehousing values('2025-02-04-22-12-32','c1g435','玛瑙手链','33','玛瑙','230','2000','无')"));
//    ret = query.exec(QString::fromLocal8Bit("insert into warehousing values('2025-02-05-22-12-32','c1g435','玛瑙手链','32','玛瑙','230','6000','无')"));
//    ret = query.exec(QString::fromLocal8Bit("insert into warehousing values('2025-02-06-22-12-32','c1g435','玛瑙手链','31','玛瑙','230','3000','无')"));
//    ret = query.exec(QString::fromLocal8Bit("insert into warehousing values('2025-02-07-22-12-32','c1g435','玛瑙手链','31','玛瑙','230','6000','无')"));
//    ret = query.exec(QString::fromLocal8Bit("insert into warehousing values('2025-02-08-22-12-32','c1g435','玛瑙手链','13','玛瑙','230','8000','无')"));

    //出库记录1月

    //query.exec(QString::fromLocal8Bit("create table delivery(time varchar(50) primary key,id varchar(50),name varchar(50),num varchar(50),type varchar(50),cost varchar(50),price varchar(50),remarks varchar(100))"));
//ret=query.exec(QString::fromLocal8Bit("create table delivery(id varchar(50), time timestamp default current_timestamp, name varchar(50) not null, num int not null check (num > 0), type varchar(50), cost decimal(10, 2) not null check (cost >= 0), price decimal(10, 2) not null check (price >= 0), remarks varchar(100), primary key (id), foreign key (id) references products(id))"));
 //ret=query.exec(QString::fromLocal8Bit("drop TABLE delivery;"));
    ret = query.exec(QString::fromLocal8Bit("CREATE TABLE delivery (record_id INTEGER PRIMARY KEY AUTOINCREMENT,  time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, name VARCHAR(50) NOT NULL, num INT NOT NULL CHECK (num > 0), type VARCHAR(50), cost DECIMAL(10, 2) NOT NULL CHECK (cost >= 0), price DECIMAL(10, 2) NOT NULL CHECK (price >= 0), remarks VARCHAR(100), product_id VARCHAR(50) NOT NULL,FOREIGN KEY (product_id) REFERENCES products(id));"));


    // 出库记录1月
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('e24d35', '翡翠玉珠', 12, '翡翠', 220.00, 2640.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 32, '玛瑙', 230.00, 7360.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('a2b3c4', '和田玉手镯', 33, '和田玉', 300.00, 9900.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('d4e5f6', '岫岩玉挂件', 34, '岫岩玉', 150.00, 5100.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('g7h8i9', '独山玉雕', 53, '独山玉', 200.00, 10600.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('j1k2l3', '绿松石项链', 36, '绿松石', 180.00, 6480.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('m4n5o6', '青金石耳环', 37, '青金石', 120.00, 4440.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('p7q8r9', '琥珀戒指', 13, '琥珀', 250.00, 3250.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('s1t2u3', '水晶摆件', 37, '水晶', 100.00, 3700.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('v4w5x6', '海蓝宝', 13, '海蓝宝', 170.00, 2210.00, '无')"));

    // 出库记录2月
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('e24d35', '翡翠玉珠', 12, '翡翠', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 32, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 33, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 14, '玛瑙', 230.00, 2000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 53, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 36, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 37, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 8000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 17, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 8000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('e24d35', '翡翠玉珠', 12, '翡翠', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 32, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 33, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 34, '玛瑙', 230.00, 2000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 23, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 36, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 37, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 23, '玛瑙', 230.00, 8000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 37, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 23, '玛瑙', 230.00, 8000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('e24d35', '翡翠玉珠', 12, '翡翠', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 32, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 33, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 34, '玛瑙', 230.00, 2000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 53, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 36, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 57, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 8000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 37, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 8000.00, '无')"));

    // 出库记录3月
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('e24d35', '翡翠玉珠', 12, '翡翠', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 52, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 33, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 34, '玛瑙', 230.00, 2000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 36, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 37, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 8000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 37, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 8000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('e24d35', '翡翠玉珠', 12, '翡翠', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 32, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 33, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 34, '玛瑙', 230.00, 2000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 13, '玛瑙', 230.00, 6000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 36, '玛瑙', 230.00, 3000.00, '无')"));
    query.exec(QString::fromLocal8Bit("insert into delivery (product_id, name, num, type, cost, price, remarks) values('c1g435', '玛瑙手链', 37, '玛瑙', 230.00, 6000.00, '无')"));
    qDebug()<<"ddddddddd"<<ret;
    qDebug()<<"ddddddddd"<<query.lastError();
    database.close();
}

DataBasePri::~DataBasePri()
{

}

QVector<QVector<QString>> DataBasePri::queryAll(QString tablename)
{
    if (! DataBasePri::database.open()){//打开数据库
        qCritical() << DataBasePri::database.lastError().text();
    }
    QSqlQuery query(DataBasePri::database);
    QString statement = QString("SELECT * FROM %1").arg(tablename);
    query.exec(statement);
    QVector<QVector<QString>> retvector;
    QVector<QString> vectorstr;
    int midsize = 0;
    while(query.next())
    {
        vectorstr.clear();
        midsize = query.size();
        for(int i = 0; i < 40;i++ ){
            vectorstr.append(query.value(i).toByteArray());
        }
        retvector.append(vectorstr);
    }
    DataBasePri::database.close();
    return retvector;
}
